package com.app.utils.util.view.expression.listener;

import android.graphics.Color;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;

import java.util.ArrayList;

/**
 * 适用于文字点击的监听
 * Created by xuxinghai on 2016/8/23.
 */
public class Clickable extends ClickableSpan implements View.OnClickListener {

    private ClickListener clickListener;
    private int position;
    private ArrayList<Object> parms;
    private OneObjectClickListener oneObjectClickListener;
    private Object object;

    public Clickable(ClickListener clickListener, int position,ArrayList<Object> parms) {
        this.clickListener = clickListener;
        this.position = position;
        this.parms = parms;
    }

    /**
     * 只传一个 object 的 点击事件
     *
     * @param oneObjectClickListener
     * @param object
     */
    public Clickable(OneObjectClickListener oneObjectClickListener, Object object) {
        this.oneObjectClickListener = oneObjectClickListener;
        this.object = object;
    }


    @Override
    public void onClick(View v) {

        if(clickListener != null){
            clickListener.click(position,parms);
        }

        if(oneObjectClickListener != null){
            oneObjectClickListener.click(object);
        }

    }

    @Override
    public void updateDrawState(TextPaint ds) {
        // TODO Auto-generated method stub
        super.updateDrawState(ds);

        ds.setColor(Color.WHITE); // 设置文件颜色
        ds.setUnderlineText(false);
    }

    public interface ClickListener {
        public void click(int position,ArrayList<Object> parms);
    }




    public interface OneObjectClickListener{
        void click(Object parms);
    }

}
